Imports MbUnit.Framework
Public Class Util

    Public Sub WriteConfigFileToDir(ByVal fileName As String, ByVal newFileName As String)
        Dim ns As String
        Dim asm As System.Reflection.Assembly
        asm = Me.GetType.Assembly
        ns = Me.GetType.Namespace
        Dim st As IO.Stream = asm.GetManifestResourceStream(ns + "." + fileName)

        Assert.IsNotNull(st, "Manifest stream for {0} does not exist", fileName)
        Dim tw As New IO.FileStream(newFileName, IO.FileMode.Create)
        Dim buff((1024 * 4) - 1) As Byte
        Dim len As Integer
        Do
            len = st.Read(buff, 0, buff.Length - 1)
            tw.Write(buff, 0, len)
        Loop While len > 0
        tw.Close()
        st.Close()
    End Sub

    Public Sub WriteConfigFileToDir(ByVal fileName As String, ByVal dirName As String, ByVal newFileName As String)
        WriteConfigFileToDir(fileName, IO.Path.Combine(dirName, newFileName))
    End Sub

    Public Function GetConfigFileAsString(ByVal fileName As String) As String
        Dim ns As String
        Dim asm As System.Reflection.Assembly
        asm = Me.GetType.Assembly
        ns = Me.GetType.Namespace
        Dim st As IO.Stream = Nothing
        Dim sr As IO.StreamReader = Nothing
        Try
            st = asm.GetManifestResourceStream(ns + "." + fileName)
            Assert.IsNotNull(st, "Manifest stream for {0} does not exist", fileName)

            sr = New IO.StreamReader(st)
            Return sr.ReadToEnd

        Finally
            sr.Close()
            st.Close()
        End Try
    End Function



End Class
